<!DOCTYPE html>
<html lang="zh-cn">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
	<title>产品1</title>

	<link href="__ROOT__/static/css/bootstrap.min.css" rel="stylesheet" />
	<style>
		.caidan a:link {
			color: gray;
			text-decoration: none
		}

		/* 未访问链接 */

		.caidan a:visited {
			color: blue;
			text-decoration: none
		}

		/* 已访问链接 */

		.caidan a:hover {
			color: blue;
			text-decoration: none
		}

		/* 用户鼠标悬停 */

		.caidan a:active {
			color: blue;
			text-decoration: none
		}

		/* 激活链接 */
	</style>

</head>

<body>

<pre>
    <b>下面的代码实际运行在微信测试号上 由 http://www.hyhthjk.com.cn/note.php/wx/Upload.php 实现|</b>
    public function  http_curl($url,$data=null){
        
                //1.初始化，创建一个新cURL资源
                 
                $ch = curl_init();
                 
                //2.设置URL和相应的选项
                 
                curl_setopt($ch, CURLOPT_URL, $url);
                 
                //curl_setopt($ch, CURLOPT_HEADER, 0);
                //如果data 不为空，则是要上传文件
                 if(!empty($data)){
                     curl_setopt($ch,CURLOPT_POST,1);
                     
                     curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
                 }
        
        
                curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//禁止curl资源直接输出
                //3.抓取URL并把它传递给浏览器
                 
                $opt=curl_exec($ch);
                     
        
                //4.关闭cURL资源，并且释放系统资源
                 
                curl_close($ch);
                return $opt;
            }
            
            public function  get_token(){
                $appid="wx4f295a95a89349e2";
                $secret="e330d58176e6be80780634f3d14deebc";
        
                $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential & appid={ $appid } & secret={ $ secret}";
               //用http_curl发给微信 微信的反回值计入$json
                $json=$this->http_curl($url);
                $result=json_decode($json);
                // dump($result->access_token);
                return $result->access_token;
            }
        
        
            /***
             * 上传菜单 只能在测试号 使用
             */
            public function  up(){
                $token = $this->get_token();
            //	dump($token);
            //	exit;
                $url="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=  { $token } ";
                $data = '{
                    "button": [
                        {
                            "type": "click", 
                            "name": "哈12", 
                            "key": "V1001_TODAY_MUSIC"
                        }, 
                        {
                            "name": "影视", 
                            "sub_button": [
                                {
                                    "type": "view", 
                                    "name": "搜索", 
                                    "url": "http://www.soso.com/"
                                }, 
                                {
                                    "type": "click", 
                                    "name": "赞一下我们", 
                                    "key": "V1001_GOOD"
                                }
                            ]
                        }
                    ]
                }';
            // result 是反回的参数
            $result= $this->http_curl($url,$data);
        
            dump($result);
        
            }

</pre>

	<!--公共js区-->
	<script src="__ROOT__/static/js/jquery.min.js"></script>
	<script src="__ROOT__/static/js/bootstrap.min.js"></script>
</body>

</html>